﻿using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace BackCodeVerify
{
    internal class Program
    {
        static void Main(string[] args)
        {
        }
    }

    public class BankCardService
    {
        // 银联生产调用地址
        private const string ApiUrl = "https://auth.95516.com/authonl/onlineAuth/rest/verify/bankcard";

        // 发送请求
        private readonly HttpClient _httpClient;

        public BankCardService(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }

        // 验证银行卡信息的公共方法
        public async Task<bool> VerifyBankCardInfoAsync(BankCardVerificationPostModel param)
        {


            // 发送POST请求
            var response = await _httpClient.PostAsync(ApiUrl, param);

            if (response.IsSuccessStatusCode)
            {
                // 解析响应数据
                string result = await response.Content.ReadAsStringAsync();

                var responseData = JsonConvert.DeserializeObject<BankCardVerificationResponse>(result);

                // 根据第三方API的响应结果返回验证结果
                return responseData?.responseCode == "00";
            }

            // 如果请求失败，返回false
            return false;
        }
    }

    // 银联返回的结构
    public class BankCardVerificationResponse
    {
        //应答码
        public string responseCode { get; set; }

        //应答消息
        public string message { get; set; }

        //应答报文
        public Dictionary<object,object> data { get; set; }
    }

    //请求数据
    public class BankCardVerificationPostModel : HttpContent
    {
        // 商户id
        public string appId { get; set; }

        public string appPwd { get; set; }

        public Dictionary<object, object> data { get; set; }

        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            throw new NotImplementedException();
        }

        protected override bool TryComputeLength(out long length)
        {
            throw new NotImplementedException();
        }
    }

    public class MessageInfo
    {
        //查询类型
        public string tradeType { get; set; }

        //姓名
        public string cardNo { get; set; }

        //姓名
        public string customerNm { get; set; }

        //手机号
        public string phoneNo { get; set; }

        //证件号
        public string certifId { get; set; }

        //证件类型
        public string certifTp { get; set; }

        //银行卡CVN2
        public string CVN2 { get; set; }

        //银行卡有效期
        public string expired { get; set; }

        //订单号
        public string orderId { get; set; }

        //交易场景编码
        public string transCode { get; set; }



    }

}
